package com.ruoyi.epidemic.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.epidemic.mapper.TbPolicyMapper;
import com.ruoyi.epidemic.domain.TbPolicy;
import com.ruoyi.epidemic.service.ITbPolicyService;

import javax.annotation.Resource;

/**
 * 政策解读Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-03-21
 */
@Service
public class TbPolicyServiceImpl implements ITbPolicyService 
{
    @Resource
    private TbPolicyMapper tbPolicyMapper;

    /**
     * 查询政策解读
     * 
     * @param id 政策解读主键
     * @return 政策解读
     */
    @Override
    public TbPolicy selectTbPolicyById(Long id)
    {
        return tbPolicyMapper.selectTbPolicyById(id);
    }

    /**
     * 查询政策解读列表
     * 
     * @param tbPolicy 政策解读
     * @return 政策解读
     */
    @Override
    public List<TbPolicy> selectTbPolicyList(TbPolicy tbPolicy)
    {
        return tbPolicyMapper.selectTbPolicyList(tbPolicy);
    }

    /**
     * 新增政策解读
     * 
     * @param tbPolicy 政策解读
     * @return 结果
     */
    @Override
    public int insertTbPolicy(TbPolicy tbPolicy)
    {
        SysUser sysUser = tbPolicyMapper.selectUser(tbPolicy.getAdminId());
        tbPolicy.setAdminName(sysUser.getUserName());
        System.out.println(sysUser);
        return tbPolicyMapper.insertTbPolicy(tbPolicy);
    }

    /**
     * 修改政策解读
     * 
     * @param tbPolicy 政策解读
     * @return 结果
     */
    @Override
    public int updateTbPolicy(TbPolicy tbPolicy)
    {
        return tbPolicyMapper.updateTbPolicy(tbPolicy);
    }

    /**
     * 批量删除政策解读
     * 
     * @param ids 需要删除的政策解读主键
     * @return 结果
     */
    @Override
    public int deleteTbPolicyByIds(Long[] ids)
    {
        return tbPolicyMapper.deleteTbPolicyByIds(ids);
    }

    /**
     * 删除政策解读信息
     * 
     * @param id 政策解读主键
     * @return 结果
     */
    @Override
    public int deleteTbPolicyById(Long id)
    {
        return tbPolicyMapper.deleteTbPolicyById(id);
    }

    @Override
    public List<TbPolicy> getList(String title) {
        QueryWrapper<TbPolicy> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(title)){
            wrapper.like("title",title);
        }
        return tbPolicyMapper.selectList(wrapper);
    }
}
